package org.Help_Desk.Controllers;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.Help_Desk.Entity.Employee;
import org.Help_Desk.Model.DBConnection;
import org.Help_Desk.Model.DatabaseConnection;

/**
 * Servlet implementation class ShowAccount
 */
@WebServlet("/ShowAccount")
public class ShowAccount extends HttpServlet {
	private static final long serialVersionUID = 1L;
	RequestDispatcher rd;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ShowAccount() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
    @Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("Servlet Called");
		PrintWriter out = response.getWriter();
		out.println("Servlet Called");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
    @Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		System.out.println("here1");
		
		String btn=request.getParameter("btn");
		if(btn.equals("submit"))
		{
		
			rd=request.getRequestDispatcher("MyAccount.jsp");
			rd.forward(request, response);
		}
                else if(btn.equals("Save"))
                {			
			System.out.println("heresave");
			Employee emp=new Employee();
			String str=request.getParameter("employeeid");
                        System.out.println(str);
			emp.setEmployeeid(Integer.parseInt(str));
			emp.setAddress(request.getParameter("address"));
			emp.setContactNumber(request.getParameter("contactnumber"));
			emp.setDOB(request.getParameter("dateofbirth"));
                        
                    try {
                           emp.UpdateEmployee();
                           PrintWriter out = response.getWriter();
                           out.println("Updated Successfully");
                        } catch (SQLException ex) {
                            Logger.getLogger(ShowAccount.class.getName()).log(Level.SEVERE, null, ex);
                        }
			 
		}
	}
}
		
